import json
import matplotlib.pyplot as plt
with open('../data/deadpool_apis_data.txt','r') as f:
    data = json.load(f)
    # print(type(data))
    # 相同tag标注下的接口协议统计
    dic = {}
    for i in range(len(data)):
        for j in data[i]['tags']: ## i是每一个api
            if j in dic: ## j是类别
                if data[i]['versions'][0]['style'] in dic[j]:
                    dic[j][data[i]['versions'][0]['style']] += 1
                else:
                    dic[j][data[i]['versions'][0]['style']] = 1
            else:
                dic[j] = {data[i]['versions'][0]['style']:1}
    # print(dic)
    for i in dic: # dic = {tag1:{接口协议:个数,接口协议:个数,...},tag2:{接口协议:个数,接口协议:个数,...},...}
        x_data = [key for key in dic[i]]
        y_data = [value for value in dic[i].values()]
        # print(i)
        # print(x_data)
        # print(y_data)
        for j in range(len(x_data)):
            plt.bar(x_data[j],y_data[j])
        
        plt.title(i)
        # plt.xlabel("接口协议")
        # plt.ylabel("个数")

        # plt.rcParams["font.sans-serif"] = ['SimHei']
        # plt.rcParams["axes.unicode_minus"] = False

        plt.savefig("../output/output3/"+ i +".png")
        plt.close()